Skip to content

Conversation

@chrchr-github
Copy link
Collaborator

No description provided.

const Library::Container* library = getLibraryContainer(tok->tokAt(-2)->astOperand1());
const Library::Container::Yield y = library->getYield(tok->strAt(-1));
if (y == Library::Container::Yield::AT_INDEX || y == Library::Container::Yield::ITEM) {
if (contains({Library::Container::Yield::AT_INDEX, Library::Container::Yield::ITEM, Library::Container::Yield::BUFFER, Library::Container::Yield::BUFFER_NT}, y)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not correct, The buffer returns a pointer not a reference so it should not be used here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function is called getLifetimeTokens() though?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its get the lifetime of a reference. Thats why the it only follows the function that return references(see here). Its similar to followReferences, but different as it will get the parent lifetime of a reference as well.

Originally, it was called getLifetimeVariable(and there is still an overload for this), but was renamed to getLifetimeTokens so it can handle expressions and multiple lifetimes.

The lifetime of pointers are set in valueflow in the token. For pointer to containers data() method, we set the lifetime here:

master.errorPath.emplace_back(parent->tokAt(2), "Pointer to container is created here.");

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no mention of pointers or references anywhere regarding those functions. But apparently the issue was in checkConstVariable().

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, that is my fault entirely since I wrote and named this function originally.

@sonarqubecloud
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants